<template>
	<view style="padding-bottom: 120rpx;">
		<u-navbar v-if="!$isWeixin()" :customBack="backToHome" :title="title" :titleBold="true" :background="{ backgroundColor: '#ffffff' }" :is-fixed="true"></u-navbar>
		<u-tabs active-color="#FF7A23" :list="tabList" :current="tabIndex" @change="index => (tabIndex = index)"></u-tabs>

		<view v-if="tabIndex == 1"><relations :list="This_Dealer_RelationList"></relations></view>

		<view class="" v-if="tabIndex == 2">
			<u-cell-item title="一级经销商名称" :arrow="false" :value="First_Dealer_BaseInfo.Name"></u-cell-item>
			<u-cell-item :border-bottom="false" title="二级经销商名称" :arrow="false" :value="Double_Dealer_BaseInfo.Name"></u-cell-item>

			<store-information :data="Door_Dealer_BaseInfo"></store-information>
		</view>

		<view class="" v-show="tabIndex == 0">
			<store-photo-form ref="storePhotoForm"></store-photo-form>

			<u-cell-item title="门店等级" :arrow="false">
				<u-radio-group v-model="form.Grade">
					<u-radio :name="1">A</u-radio>
					<u-radio :name="2">B</u-radio>
					<u-radio :name="3">C</u-radio>
				</u-radio-group>
			</u-cell-item>
			<u-cell-item title="模块化" :arrow="false">
				<u-radio-group v-model="form.Module">
					<u-radio :name="1">模块</u-radio>
					<u-radio :name="2">非模块</u-radio>
				</u-radio-group>
			</u-cell-item>
			<u-cell-item title="门头化" :arrow="false">
				<u-radio-group v-model="form.IsDoor">
					<u-radio :name="1">门头</u-radio>
					<u-radio :name="2">非门头</u-radio>
				</u-radio-group>
			</u-cell-item>
			<u-cell-item title="样机类型" :arrow="false">
				<u-checkbox-group @change="onCheckboxChange">
					<u-checkbox name="1" v-for="(item, index) in prototypeList" :key="index" :name="item.name" v-model="item.checked">{{ item.label }}</u-checkbox>
				</u-checkbox-group>
			</u-cell-item>
			<u-cell-item title="精选门店" :arrow="false" :border-bottom="false">
				<u-radio-group v-model="form.IsGoodDoor">
					<u-radio :name="1">是</u-radio>
					<u-radio :name="0">否</u-radio>
				</u-radio-group>
			</u-cell-item>

			<block v-if="showReview">
				<u-gap :height="10" bg-color="#f5f5f5"></u-gap>
				<review-form ref="applyForm"></review-form>
			</block>
		</view>

		<view class="btn-group-fixed"><u-button v-if="showReview" type="warning" @click="submit">保存提交</u-button></view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			title: '门店照片审核',
			InfoId: '',

			tabList: [{ name: '门店照片' }, { name: '销售业务关系' }, { name: '基本信息' }],
			tabIndex: 0,

			relationsMetaData: {},

			DealerAuditInfo: {},
			DoorPhotoAuditInfo: {},
			DoorPhotoList: [],
			Door_Dealer_BaseInfo: {},
			Double_Dealer_BaseInfo: {},
			First_Dealer_BaseInfo: {},
			This_Dealer_OtherInfo: {},
			This_Dealer_RelationList: [],

			prototypeList: [{ name: 1, label: '空壳样机', checked: false }, { name: 2, label: '实体样机', checked: false }],
			selectedPrototype: [],

			showReview: false,

			form: {
				DealerId: null,
				Id: null,
				PhotoList: [],
				AuditRemark: '',
				State: null,

				Grade: null,
				Module: null,
				IsDoor: null,
				IsPrototype: null,
				IsGoodDoor: null
			}
		};
	},

	onLoad(options) {
		if (options.DealerId) {
			this.form.DealerId = options.DealerId;
		}
		if (options.InfoId) {
			this.InfoId = options.InfoId;
			this.form.Id = options.InfoId;
		}

		this.getData();
		this.$setTitle(this.title);
	},

	methods: {
		backToHome() {
			uni.navigateBack();
		},

		onCheckboxChange(e) {
			this.selectedPrototype = e;
		},

		submit() {
			const applyForm = this.$refs.applyForm.form;
			const storePhotoForm = this.$refs.storePhotoForm;

			this.form.AuditRemark = applyForm.AuditRemark;
			this.form.State = applyForm.State;
			this.form.PhotoList = storePhotoForm.list;
			this.form.IsPrototype = this.selectedPrototype.join(',');

			if (!this.form.State) {
				this.$u.toast('请选择审核状态');
				return false;
			}

			this.$u.api.approvalDoorPhoto(this.form).then(res => {
				const { ResultCode, ResultMessage } = res;
				if (ResultCode === 1) {
					this.$u.toast(ResultMessage);

					setTimeout(() => {
						uni.navigateBack();
					}, 1000);
				}
			});
		},

		getData() {
			this.$u.api
				.getPhotoInformationReviewDetail({
					InfoId: this.InfoId
				})
				.then(res => {
					const {
						ResultCode,
						DataBaseInfo,
						DealerAuditInfo,
						DoorPhotoAuditInfo,
						AuditForList,
						DoorPhotoList,
						Door_Dealer_BaseInfo,
						Double_Dealer_BaseInfo,
						First_Dealer_BaseInfo,
						This_Dealer_RelationList
					} = res;

					if (ResultCode === 1) {
						if (this.vuex_user.ManagerId == res.NextManagerId) {
							this.showReview = true;
						}

						this.DataBaseInfo = DataBaseInfo;
						this.DealerAuditInfo = DealerAuditInfo;
						this.DoorPhotoAuditInfo = DoorPhotoAuditInfo;
						this.DoorPhotoList = DoorPhotoList;
						this.Door_Dealer_BaseInfo = Door_Dealer_BaseInfo;
						this.Double_Dealer_BaseInfo = Double_Dealer_BaseInfo;
						this.First_Dealer_BaseInfo = First_Dealer_BaseInfo;
						this.This_Dealer_RelationList = This_Dealer_RelationList;
						this.AuditForList = AuditForList;

						if (This_Dealer_RelationList) {
							this.This_Dealer_RelationList = This_Dealer_RelationList;
						}

						if (DealerAuditInfo) {
							this.DealerAuditInfo = DealerAuditInfo;
						}

						if (DoorPhotoAuditInfo) {
							this.DoorPhotoAuditInfo = DoorPhotoAuditInfo;
						}

						if (DoorPhotoList) {
							this.DoorPhotoList = DoorPhotoList;
						}

						if (Door_Dealer_BaseInfo) {
							this.Door_Dealer_BaseInfo = Door_Dealer_BaseInfo;
						}

						if (Double_Dealer_BaseInfo) {
							this.Double_Dealer_BaseInfo = Double_Dealer_BaseInfo;
						}

						if (First_Dealer_BaseInfo) {
							this.First_Dealer_BaseInfo = First_Dealer_BaseInfo;
						}

						this.form.Module = DoorPhotoAuditInfo.Module;
						this.form.Grade = DoorPhotoAuditInfo.Grade;
						this.form.IsDoor = DoorPhotoAuditInfo.IsDoor;
						this.form.IsPrototype = DoorPhotoAuditInfo.IsPrototype;
						this.form.IsGoodDoor = DoorPhotoAuditInfo.IsGoodDoor;

						this.$refs.storePhotoForm.initPhotoList(DoorPhotoList);
					}
				});
		},

		init() {
			this.$u.api
				.getInitInformationUpdateDetail({
					DealerId: this.form.DealerId
				})
				.then(res => {
					console.log(res);
					const {
						ResultCode,
						ShowLevel,
						DealerAuditInfo,
						DoorPhotoAuditInfo,
						DoorPhotoList,
						Door_Dealer_BaseInfo,
						Double_Dealer_BaseInfo,
						First_Dealer_BaseInfo,
						This_Dealer_OtherInfo,
						This_Dealer_RelationList,
						DirectorList,
						SalseList,
						DealerTerminalList,
						TeamList,
						SeniorDealerTerminalList,
						DealerDivisionList,
						RegionalDirectorList,
						SalesServiceList
					} = res;

					if (ResultCode === 1) {
						this.ShowLevel = ShowLevel;

						if (This_Dealer_RelationList) {
							this.This_Dealer_RelationList = This_Dealer_RelationList;
						}

						if (DealerAuditInfo) {
							this.DealerAuditInfo = DealerAuditInfo;
						}

						if (DoorPhotoAuditInfo) {
							this.DoorPhotoAuditInfo = DoorPhotoAuditInfo;
						}

						if (DoorPhotoList) {
							this.DoorPhotoList = DoorPhotoList;
						}

						if (Door_Dealer_BaseInfo) {
							this.Door_Dealer_BaseInfo = Door_Dealer_BaseInfo;
						}

						if (Double_Dealer_BaseInfo) {
							this.Double_Dealer_BaseInfo = Double_Dealer_BaseInfo;
						}

						if (First_Dealer_BaseInfo) {
							this.First_Dealer_BaseInfo = First_Dealer_BaseInfo;
						}

						if (This_Dealer_OtherInfo) {
							this.This_Dealer_OtherInfo = This_Dealer_OtherInfo;
						}

						this.$refs.storePhotoForm.initPhotoList(DoorPhotoList);
					}
				});
		}
	}
};
</script>

<style lang="scss"></style>
